﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Classes;
using FlightSystemDBLayer;

namespace FlightSystemControlLayer
{
    public class BookingCtr
    {
        IBooking bookDB;
        private static Object ob = new Object();
        public BookingCtr() 
        {
            bookDB = new DBBooking();
            
        }
        public void Book(Connection conn, int seatsWanted, string fname, string lname, string address, string country, string phone, string email, string passport)
        {
            Booking book = new Booking();
            
            try
            {
               bookDB.writeConnection(conn, seatsWanted);
               foreach (Reservation item in book.book(conn, seatsWanted, fname, lname, address, country, phone, email, passport))
                 {
                   lock(ob){
                   
                    bookDB.writeData(item);
                   }
                 } 
            }
            catch (Exception e)
            {

                Console.WriteLine(e.StackTrace);
            }
            
            
        }
    }
}
